package com.bk.bands.model;


import com.bk.bands.common.Rectangle;
import com.bk.bands.evaluate.Evaluable;
import com.bk.bands.evaluate.Evaluator;
import com.bk.bands.print.Paper;
import com.bk.bands.runtime.BandsException;

/**
 * Created by IntelliJ IDEA.
 * User: sg0891787
 * Date: 3/5/12
 * Time: 11:11 AM
 */
public class TextField extends Field implements Evaluable
{
   private Border border;
   private String value;
   private Style refStyle;
   private Style ownStyle;

   public Border getBorder()
   {
      return border;
   }

   public void setBorder(Border border)
   {
      this.border = border;
   }

   public String getValue()
   {
      return value;
   }

   public void setValue(String value)
   {
      this.value = value;
   }

   public Style getRefStyle()
   {
      return refStyle;
   }

   public void setRefStyle(Style style)
   {
      this.refStyle = style;
   }

   public Style getOwnStyle()
   {
      return ownStyle;
   }

   public void setOwnStyle(Style ownStyle)
   {
      this.ownStyle = ownStyle;
   }

   public Style getStyle()
   {
      if(refStyle == null)
      {
         return ownStyle;
      }
      return refStyle;
   }

   public Field evaluate(Evaluator evaluator)
   {
      TextField evaluatedField = (TextField) clone();
      evaluatedField.setValue(evaluator.evaluate(getValue()));
      return evaluatedField;
   }

   public Field clone()
   {
      TextField copy = (TextField) super.clone();
      copy.setRefStyle(getRefStyle());
      copy.setBorder(getBorder());
      copy.setOwnStyle(getOwnStyle());
      copy.setValue(getValue());
      return copy;
   }

   @Override
   protected Field duplicate()
   {
      return new TextField();
   }

   @Override
   public void print(Paper paper) throws BandsException
   {
      paper.drawText(getLabel(),getStyle(),new Rectangle(getPosition(),getSize()),getBorder());
   }
}
